package com.songcha.library_common.util

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities


class NetworkUtil {
    companion object {
        open fun isNetworkAvailable(context: Context?): Boolean {
            if (context == null) {
                return true
            }
            var manager = context?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                var networkCapabilities: NetworkCapabilities? =
                        manager.getNetworkCapabilities(manager.activeNetwork)
                                ?: return false
                return networkCapabilities!!.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
            } else {
                return manager.activeNetworkInfo?.isConnected ?: false
            }

        }
    }

}